<?php

/* @var $this yii\web\View */

use yii\helpers\Html;
use yii\helpers\Url;
use app\model\Member;
use yii\grid\GridView;
use yii\widgets\DetailView;
use yii\data\ActiveDataProvider;

$this->title = '会员注册申请管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="page-title">
  <div>
    <h1><i class="fa fa-envelope"></i> 会员注册申请管理</h1>
  </div>

</div>
<div class='card'>

  <?php
  echo GridView::widget([
  'dataProvider' => $dataProvider,
  'columns' => [
  ['class' => 'yii\grid\CheckboxColumn'],
  // 数据提供者中所含数据所定义的简单的列
  // 使用的是模型的列的数据
  [
    'header'=>'<div class="btn-group pull-right">
      <a class="btn btn-info btn-sm del-reg-user"><i class="fa fa-trash-o"></i></a>
    </div>',
    'content'=>function ($model, $key, $index, $column) {
      $output='<span class="alert-info" style="border-radius:10px;padding:2px 8px;"><b>'.($index+1).'</b></span><br>';
      $output .= DetailView::widget([
        'model' => $model,
        'attributes' => [
            'name',
            'phone',
            'realname',
            'sfzid',
            'bankcardid',
            'opencardbank',
            'alipay',
            'tjr'
        ],
        'options'=>['class' => 'table table-striped table-bordered detail-view']
    ]);
    $output.= '<label>手持身份证照片:</label><br><img src="'.Url::toRoute(is_null($model->tjm)?'':$model->tjm).'" class="sfz-preview"><br>';
    $output.= '<br><div class="reg-prove-block">';
    if($model->status==0){
      $output.= '<label>审核:</label>&nbsp;&nbsp;<a class="btn btn-warning reg-prove-yes" style="cursor:pointer;"><i class="fa fa-lg fa-check-circle"></i>&nbsp;是</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-warning reg-prove-no" style="cursor:pointer;"><i class="fa fa-lg fa-times-circle"></i>&nbsp;否</a>';
    }else if($model->status==2){
      $output.= '<h3 class="alert-danger">审核不通过</h3>';
    }else if($model->status==1){
      $output.= '<h3 class="alert-info">审核通过</h3>';
    }
    $output.= '</div>';
        return $output;
    },
    ],
  ],
  'tableOptions' => [
    'class' => 'table'
  ],
  ]);
  ?>
</div>
<?php $this->beginBlock('reg-prove-js') ?>
  //审核注册
  $('.reg-prove-yes').click(function(){
    var datakey=$(this).parents('tr').first().attr('data-key');
    $.ajax({
      url:"<?=Url::toRoute('site/regproveajax')?>",
      type:"get",
      datatype:"json",
      cache:false,
      data:{
        datakey:datakey,
        pass:1
      },
      success:function(data){
         var obj = JSON.parse(data);
         if(obj.errcode===0){
           var $row = $('tr[data-key="'+datakey+'"]');
           var $datatd = $row.find('td:eq(1)');
           $datatd.find('.reg-prove-block').html('<h3 class="alert-info">审核通过</h3>');

         }else{
           alert('审核失败。');
         }
      },
      error:function(jqXHR,textStatus,errorThrown){
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
        $('.compose').slideToggle();
      }
    });
  });
  $('.reg-prove-no').click(function(){
    var datakey=$(this).parents('tr').first().attr('data-key');
    $.ajax({
      url:"<?=Url::toRoute('site/regproveajax')?>",
      type:"get",
      datatype:"json",
      cache:false,
      data:{
        datakey:datakey,
        pass:0
      },
      success:function(data){
         var obj = JSON.parse(data);
         if(obj.errcode===0){
           var $row = $('tr[data-key="'+datakey+'"]');
           var $datatd = $row.find('td:eq(1)');
           $datatd.find('.reg-prove-block').html('<h3 class="alert-danger">审核不通过</h3>');

         }else{
           alert('审核失败。');
         }
      },
      error:function(jqXHR,textStatus,errorThrown){
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
        $('.compose').slideToggle();
      }
    });
  });

  $('.del-reg-user').click(function(){
    var mykeys = $('.grid-view').yiiGridView('getSelectedRows');
    $.ajax({
      url:"<?=Url::toRoute('site/delreguserajax')?>",
      type:"get",
      datatype:"json",
      cache:false,
      data:{
        keys:mykeys
      },
      success:function(data){
         var obj = JSON.parse(data);
         if(obj.errcode===0){
           window.location.href='<?=Url::toRoute('site/regprove')?>';

         }else{
           alert('审核失败。');
         }
      },
      error:function(jqXHR,textStatus,errorThrown){
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
        $('.compose').slideToggle();
      }
    });
  });

<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['reg-prove-js'],\yii\web\View::POS_END); ?>
